define(['models/map'], function (map) {
    "use strict";

    function Route() {
        this.style = {strokeOpacity: 0.6, strokeWidth: 6, strokeColor: '#FA5858'};

        this.route = new OpenLayers.Geometry.LineString([]);
        this.routeFeature = new OpenLayers.Feature.Vector(this.route, null, this.style);

        map.routes.addFeatures([this.routeFeature]);
    };

    Route.prototype = {
        constructor: Route,
        //_decode: function (encoded, precision) {
        //    precision = Math.pow(10, -precision);
        //    var len = encoded.length, index = 0, lat = 0, lng = 0, array = [];
        //    while (index < len) {
        //        var b, shift = 0, result = 0;
        //        do {
        //            b = encoded.charCodeAt(index++) - 63;
        //            result |= (b & 0x1f) << shift;
        //            shift += 5;
        //        } while (b >= 0x20);
        //        var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
        //        lat += dlat;
        //        shift = 0;
        //        result = 0;
        //        do {
        //            b = encoded.charCodeAt(index++) - 63;
        //            result |= (b & 0x1f) << shift;
        //            shift += 5;
        //        } while (b >= 0x20);
        //        var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
        //        lng += dlng;
        //        array.push([lat * precision, lng * precision]);
        //    }
        //    return array;
        //},
        addPosition: function (position) {
            var point = new OpenLayers.Geometry.Point(position.longitude, position.latitude).transform(map.epsg4326, map.projectTo);
            this.route.addPoint(point);
            map.routes.redraw();
            console.log('drawing/route.js. addPoint: ' + JSON.stringify(position));
        }
    };

    console.log('drawing/route.js');
    return Route;
});